﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
namespace ERP.Classes
{
    public class cs_erp_khohangInfo
    {
        private int _id_khohang;
        private string _makho;
        private string _tenkho;
        private string _donviql;
        private string _diachi;
        private string _ghichu;
        private string _maql;

        public cs_erp_khohangInfo(int id_khohang, string makho, string tenkho, string donviql, string diachi, string ghichu, string maql)
        {
            this._id_khohang = id_khohang;
            this._makho = makho;
            this._tenkho = tenkho;
            this._donviql = donviql;
            this._diachi = diachi;
            this._ghichu = ghichu;
            this._maql = maql;

        }
        public cs_erp_khohangInfo()
        {
            this._id_khohang = 0;
            this._makho = " ";
            this._tenkho = " ";
            this._donviql = " ";
            this._diachi = " ";
            this._ghichu = " ";
            this._maql = " ";

        }
        public int id_khohang
        {
            get
            {
                return this._id_khohang;
            }
            set
            {
                this._id_khohang = value;
            }
        }
        public string makho
        {
            get
            {
                return this._makho;
            }
            set
            {
                this._makho = value;
            }
        }
        public string tenkho
        {
            get
            {
                return this._tenkho;
            }
            set
            {
                this._tenkho = value;
            }
        }
        public string donviql
        {
            get
            {
                return this._donviql;
            }
            set
            {
                this._donviql = value;
            }
        }
        public string diachi
        {
            get
            {
                return this._diachi;
            }
            set
            {
                this._diachi = value;
            }
        }
        public string ghichu
        {
            get
            {
                return this._ghichu;
            }
            set
            {
                this._ghichu = value;
            }
        }
        public string maql
        {
            get
            {
                return this._maql;
            }
            set
            {
                this._maql = value;
            }
        }

        public int ExcuteStoreProcedure(string storeProcedure, int option)
        {
            string[] paraName = new string[8];
            paraName[0] = "@id_khohang";
            paraName[1] = "@makho";
            paraName[2] = "@tenkho";
            paraName[3] = "@donviql";
            paraName[4] = "@diachi";
            paraName[5] = "@ghichu";
            paraName[6] = "@maql";
            paraName[7] = "@option";
            object[] paraValue = new object[8];
            paraValue[0] = this._id_khohang;
            paraValue[1] = this._makho;
            paraValue[2] = this._tenkho;
            paraValue[3] = this._donviql;
            paraValue[4] = this._diachi;
            paraValue[5] = this._ghichu;
            paraValue[6] = this._maql;
            paraValue[7] = option;
            csCSDL csdl = new csCSDL();
            int i = 0;
            i = csdl.CreateParameters(paraName, 8, paraValue);
            return csdl.ExcuteStoreProcedure(storeProcedure);
        }
        
        public int ExcuteProcedure(int option)
        {
            return this.ExcuteStoreProcedure("Proc_ERP_KHOHANG", option);
        }

        
        public int Get_Info()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                ds = csdl.OpenTable("ERP_KHOHANG", "id_khohang = " + this._id_khohang);
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    return 0;
                }
                this._id_khohang = Convert.ToInt32(ds.Tables[0].Rows[0]["id_khohang"].ToString().Trim());
                this._makho = ds.Tables[0].Rows[0]["makho"].ToString().Trim();
                this._tenkho = ds.Tables[0].Rows[0]["tenkho"].ToString().Trim();
                this._donviql = ds.Tables[0].Rows[0]["donviql"].ToString().Trim();
                this._diachi = ds.Tables[0].Rows[0]["diachi"].ToString().Trim();
                this._ghichu = ds.Tables[0].Rows[0]["ghichu"].ToString().Trim();
                this._maql = ds.Tables[0].Rows[0]["maql"].ToString().Trim();
                return 1;
            }
            catch
            {
                return -1;
            }
        }

        public DataSet Get_List()
        {
            csCSDL csdl = new csCSDL();
            DataSet ds = new DataSet("ds");
            try
            {
                string sql = "select id_khohang, makho, tenkho, donviql, diachi, ghichu, maql"
                + " from ERP_KHOHANG";
                ds = csdl.SelecSQL(sql);

                return ds;
            }
            catch
            {
                return null;
            }
        }

    }
}
